namespace Plugins.Engine.Internal
{
    using System;
    using System.Collections;
    using Plugins.Interfaces;

    [Serializable]
    internal class PluginHostService : IPluginHostService
    {
        private readonly Hashtable _hosts = new Hashtable();

        public IPluginHost Create(Guid value, string hostName, string fileName, bool isDefault)
        {
            if (hostName != null && fileName != null)
            {
                IPluginHostInternal _host = this._hosts[value] as IPluginHostInternal;
                if (_host == null)
                {
                    _host = new PluginHost(value, hostName, fileName, isDefault);
                    this._hosts[_host.Id] = _host;
                }
                return _host;
            }
            return null;
        }

        //public IPluginHost Create(string hostName, string fileName, bool isDefault)
        //{
        //    if (hostName != null && fileName != null)
        //    {
        //        IPluginHostInternal _host = this._hosts[hostName] as IPluginHostInternal;
        //        if (_host == null)
        //        {
        //            _host = new PluginHost(hostName, fileName, isDefault);
        //            this._hosts[_host.Name] = _host;
        //        }
        //        return _host;
        //    }
        //    return null;
        //}

        public void Destroy(IPluginHost loaded)
        {
            if (loaded != null)
            {
                IPluginHostInternal _host = this._hosts[loaded.Id] as IPluginHostInternal;
                if (_host != null)
                {
                    this._hosts.Remove(_host.Id);
                    //_host.Clear();
                }
            }
        }
    }
}

